import { Component, PropsWithChildren } from 'react'
import { View, Text } from '@tarojs/components'
import { AtList, AtListItem, AtIcon } from "taro-ui"
import { getInteraction } from '../../api/home'
import './index.scss'
import Taro from '@tarojs/taro'

export default class Index extends Component<PropsWithChildren> {
  state: any
  constructor(props) {
    super(props)
    this.state = {
      MsgList: []
    }
  }
  componentWillMount() { }

  componentDidMount() {
    this.getMessage()
  }

  componentWillUnmount() { }

  componentDidShow() { }

  componentDidHide() { }
  getMessage() {
    getInteraction().then((res) => {
      this.setState({
        MsgList: res.data.data
      })
    })
  }
  onClick() {
    Taro.navigateBack()
  }
  goChat() {
    Taro.navigateTo({
      url: '/pages/myChat/index'
    })
  }
  render() {
    return (
      <View className='index'>
        <View className='nav-bar-box'>
          <View className='status-bar'></View>
          <View className='title-bar'>
            <AtIcon onClick={this.onClick.bind(this)} className='icon' value='chevron-left' size='24' color='#fff'></AtIcon>
            <Text className='tit'>消息</Text>
          </View>
        </View>
        <View className='message'>
          <AtList>
            {
              this.state.MsgList?.map((item: any, index: number) => {
                return <AtListItem
                  key={index}
                  onClick={this.goChat.bind(this)}
                  title={item.name}
                  note={item.title}
                  extraText={item.time}
                  thumb={item.imgUrl}
                />
              })
            }
          </AtList>
        </View>
      </View >
    )
  }
}
